package com.yqg.manage.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

/**
 * user 实体类
 *
 * @author suzhuang
 * @since 2023-07-05
 */
@Getter
@Setter
@ApiModel(value = "User对象", description = "")
public class User implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ApiModelProperty("账号")
    private String account;

    @ApiModelProperty("用户名")
    private String username;

    @ApiModelProperty("密码")
    private String password;

    @ApiModelProperty("角色")
    private Long userRole;

    @TableField(exist = false)
    @ApiModelProperty("角色等级")
    private Long roleLevel;

    @ApiModelProperty("部门ID")
    private Long departmentId;

    @ApiModelProperty("单位ID")
    private Long unitId;

    @ApiModelProperty("性别")
    private String sex;

    @ApiModelProperty("联系方式")
    private String contact;

    @ApiModelProperty("执法证件号")
    private String identificationNumber;

    @TableField(fill = FieldFill.INSERT)
    @ApiModelProperty("创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty("更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    @ApiModelProperty("是否可用（0可用，1不可用）")
    private String isDelete;

    @TableField(exist = false)
    private String roleName;

    @TableField(exist = false)
    private String unitName;

    @TableField(exist = false)
    private String departmentName;

    /**
     * 用户为副主任，负责的单位ID
     */
    @TableField(exist = false)
    private List<Long> unitIds;


    /**
     * 查询用户时，将副主任负责的ID查询出来
     * @param unitIds id组成的字符串（使用，分割）
     */
    public void setResponsibilityUnitIds(String unitIds) {
        if (unitIds != null && !unitIds.isEmpty()) {
            this.unitIds = Arrays.stream(unitIds.split(","))
                    .map(Long::valueOf)
                    .collect(Collectors.toList());
        } else {
            this.unitIds = null;
        }
    }
}
